package net.grapsus.arduino;

import javax.swing.*;

/**
 * @author Mihai Moraru
 */
public class ArduinoPWMPin extends ArduinoPin {
	public ArduinoPWMPin(JTextField tf, double x, double y)
	{
		super(tf, x, y);
	}

	public void analogWrite(int val)
	{
		/* You do not need to call pinMode() to set the pin as an output before calling analogWrite() */
		pinMode(ArduinoCore.OUTPUT);
		if(val < 0 || val > 255)
			return;
		voltage = ArduinoCore.V_LOW+(ArduinoCore.V_HIGH-ArduinoCore.V_LOW)*val/255;
		this.repaint();
		tf.setText(Double.toString(voltage));
		tf.repaint();
	}
}
